1. Field of the Invention
The present invention relates to an assembler device and its assembling method for use in a microcomputer or other computer system, and particularly to an assembling system capable of generating an optimum object code of a small-sized program without increasing frequency of pass.
2. Description of the Related Art
As a conventional assembler device of this kind, there have been a device for assembling according to two-pass method having two passes, each pass including one execution of processing through reading an input assembler program from the head to the end by one line, and another device for assembling according to three-pass method having three passes like that.
FIG. 11 is a block diagram showing the constitution of the system in the conventional assembler device of two-pass method. The assembler device shown in FIG. 11 comprises a control section 1100 including a pass-1 processing executing unit 1110 for executing a pass-1 processing and a pass-2 processing executing unit 1120 for executing a pass-2 processing, and an auxiliary storage section 1200 for storing an assembler program 1201, a symbol table 1202 and an object module file 1203. The pass-1 processing executing unit 1110 in the control section 1100 includes a character analyzing unit 1111, a syntax analyzing unit 1112, a symbol table generating unit 1113, and a code estimating unit 1114. The pass-2 processing executing unit 1120 includes a character analyzing unit 1121, a syntax analyzing unit 1122, and a codes generating unit 1123.
Each function of each component will be described. In the pass-1 processing executing unit 1110, the character analyzing unit 1111 breaks an assembler program 1201 read from the auxiliary storage section 1200 into characters and analyzes them. The syntax analyzing unit 1112 builds syntax upon receipt of the result of the character analysis by the character analyzing unit 1111 and recognizes the syntax. The symbol table generating unit 1113 generates a symbol table 1202 upon receipt of the result of the syntax analysis by the syntax analyzing unit 1112. The code estimating unit 1114 estimates an object code upon receipt of the result of the syntax analysis by the syntax analyzing unit 1112.
This time, in the pass-2 processing executing unit 1120, the character analyzing unit 1121 breaks an assembler program 1201 read from the auxiliary storage section 1200 into characters and analyzes them. The syntax analyzing unit 1122 builds syntax upon receipt of the result of the character analysis by the character analyzing unit 1121 and recognizes the syntax. The code generating unit 1123 generates an object code for the syntax built by the syntax analyzing unit 1122 and stores it into the auxiliary storage section 1200 as an object module file 1203.
A concrete example of the object module file generated by the conventional assembler device of two-pass method having the above-mentioned structure will be described with reference to FIGS. 12 to 14.
A table shown in FIG. 13 is an example of the assembler program to be processed. In the assembler program of FIG. 13, the instructions A(1), B(2), C(3), D(4), E(6), and F(7) are statements respectively describing that a symbol of the data segment (DSEG) is referred to. The attribute of the data segment decides whether each instruction is two bytes long or three bytes long.
The segment definition A(12) is a specification statement describing that the definition of the data area visible by the two-byte instruction starts. The Labels C(9) and D(10) described after this segment definition A(12) is defined are visible by the two-byte instruction. The segment definition B(13) is a specification statement describing that the definition of the data area visible by the three-byte instruction starts. The Label E(11) described after the definition of the segment definition B(13) is visible by the three-byte instruction.
FIG. 12 is a view showing the process of generating a symbol table 1202 by the symbol table generating unit 1113 according to the operation of this conventional example. The symbol table 1202 of FIG. 12(A) shows the state after the instruction A(1) of the assembler program of FIG. 13 has been processed. At this point, it is impossible to confirm whether the "sym1" is visible by the two-byte instruction or by the three-byte instruction, so that the "sym1" is regarded as visible by the three-byte instruction. The instructions B(2), C(3), and D(4) are similarly processed and any "sym" is regarded as visible by the three-byte instruction. FIG. 12(C) is the symbol table 1202 generated at the result of the above-mentioned processing.
The symbol table 1202 of FIG. 12(D) shows the state after the Label A(5) has been processed. Since all the instructions A(1), B(2), C(3), and D(4) have been regarded as the three-byte instructions, the value of the Label A(5) becomes "CH". Also, the instructions E(6) and F(7) are regarded as the three-byte instructions.
The symbol table 1202 of FIG. 12(E) shows the state after the Label B(8) has been processed. Since the instructions E(6) and F(7) have been judged to be the three-byte instructions, the value of the Label B(8) becomes "12H". The symbol table 1202 of FIG. 12(F) shows the state after the Labels C(9) and D(10) have been processed. Both the Labels C(9) and D(10) are Labels defined in the data area visible by the two-byte instruction. The symbol table 1202 of FIG. 12(G) shows the state after the Label E(11) has been processed. The Label E(11) is a Label defined in the data area visible by the three-byte instruction. Thus, the pass-1 processing has been completed.
This time, in the pass-2 processing, the code generating unit 1123 generates an object module file 1203 on the basis of the information stored in the symbol table 1202 which has been decided through the pass-1 processing. FIG. 14 is an assembly listing generated by processing the assembler program of FIG. 13.
In the assembly listing of FIG. 14, the generation instructions E(21), F(22), G(23), and H(24) are all generated by the three-byte instruction, in spite of their reference to the Labels all defined in the data area visible by the two-byte instruction in fact. Therefore, useless object codes of four bytes in total are generated.
The assembler device of three-pass method will be described this time. As this kind of the conventional technique, there has been an assembler device, for example, disclosed in Japanese Patent Publication Laid-Open (Kokai) No. Heisei 5-257703, "An Assembler Device". FIG. 15 is a block diagram showing the constitution of the system in the assembler device of three-pass method disclosed in the same publication.
The assembler device shown in FIG. 15 comprises a control section 1300 including a pass-1 processing executing unit 1310 for executing a pass-1 processing, a pass-2 processing executing unit 1320 for executing a pass-2 processing, and a pass-3 processing executing unit 1330 for executing a pass-3 processing, and an auxiliary storage section 1200 for storing an assembler program 1201, a symbol table 1202, and an object module file 1203. The pass-1 processing executing unit 1310 in the control section 1300 includes a character analyzing unit 1311, a syntax analyzing unit 1312, and a symbol table generating unit 1313. The pass-2 processing executing unit 1320 includes a character analyzing unit 1321, a syntax analyzing unit 1322, a symbol table generating unit 1323, and a code estimating unit 1324. The pass-3 processing executing unit 1330 includes a character analyzing unit 1331, a syntax analyzing unit 1332, and a code generating unit 1333.
Each function of each component will be described. In the pass-1 processing executing unit 1310, the character analyzing unit 1311 breaks an assembler program 1201 read from the auxiliary storage section 1200 into characters and analyzes them. The syntax analyzing unit 1312 builds syntax upon receipt of the result of the character analysis by the character analyzing unit 1311 and recognizes the syntax. The symbol table generating unit 1313 generates a symbol table 1202 upon receipt of the result of the syntax analysis by the syntax analyzing unit 1312.
This time, in the pass-2 processing executing unit 1320, the character analyzing unit 1321 breaks the assembler program 1201 read from the auxiliary storage section 1200 into characters and analyzes them. The syntax analyzing unit 1322 builds syntax upon receipt of the result of the character analysis by the character analyzing unit 1321 and recognizes the syntax. The symbol table generating unit 1323 corrects the symbol table 1202 generated by the symbol table generating unit 1313 of the pass-1 processing executing unit 1310, upon receipt of the result of the syntax analysis by the syntax analyzing unit 1322. The code estimating unit 1324 estimates an object code upon receipt of the syntax analysis by the syntax analyzing unit 1322.
In the pass-3 processing executing unit 1330, the character analyzing unit 1331 breaks the assembler program 1201 read from the auxiliary storage section 1200 into characters and analyzes them. The syntax analyzing unit 1332 builds syntax upon receipt of the result of the character analysis by the character analyzing unit 1331 and recognizes the syntax. The code generating unit 1333 generates an object code for the syntax built by the syntax analyzing unit 1332 and stores it into the auxiliary storage section 1200 as an object module file 1203.
A concrete example of the object module file generated by the conventional assembler device of three-pass method having the above-mentioned structure will be described with reference to FIGS. 16 and 17. Also in this example, the assembler program shown in FIG. 13 is used as a candidate for processing.
FIG. 16 is a view showing the process of generating a symbol table 1202 by the symbol table generating unit 1313 according to the operation of the conventional example. The symbol table 1202 of FIG. 16(A) shows the state after the instruction A(1) of the assembler program of FIG. 13 has been processed. Since it is impossible to confirm at this point whether the "sym1" is visible by the two-byte instruction or by the three-byte instruction, only the name "sym1" is registered in the symbol table 1202. The instructions B(2), C(3), and D(4) are similarly processed and in any case, only the "name" is registered in the symbol table 1202. FIG. 16(C) is the symbol table 1202 generated at the result of the above-mentioned processing.
The symbol table 1202 of FIG. 16(D) shows the state after the Label A(5) has been processed. At this time, the name "lab" and the segment information "0" are registered in the symbol table 1202. Since it is impossible to confirm whether the instructions E(6) and F(7) are visible by the two-byte instruction or by the three-byte instruction, each name only is registered in the symbol table 1202.
The symbol table 1202 of FIG. 16(E) shows the state after the Label B(8) has been processed. At this time, the name "lab2" and the segment information "0" are registered in the symbol table 1202. The symbol table 1202 of FIG. 16(F) shows the state after the Labels C(9) and D(10) have been processed. Both the Labels C(9) and D(10) are Labels defined in the data area visible by the two-byte instruction. The value and the segment information are registered in the symbol table 1202. The symbol table 1202 of FIG. 16(G) shows the state after the Label E(11) has been processed. The Label E(11) is a Label defined in the data area visible by the three-byte instruction. The value and the segment information are registered in the symbol table. Thus, the pass-1 processing has been completed.
This time, in the pass-2 processing, the symbol table generating unit 1323 corrects the symbol table 1202 which has been generated in the pass-1 processing and the code estimating unit 1324 estimates a code.
The symbol table 1202 of FIG. 16(H) shows the state after the instructions A(1), B(2), C(3), and D(4) have been processed. Referring to the segment information of the symbol table 1202, the instructions A(1), C(3), and D(4) are visible by the two-byte instruction, while the instruction B(2) is visible by the three-byte instruction. Therefore, the value of the Label A(5) becomes "9H".
The symbol table 1202 of FIG. 16(I) by the symbol table generating unit 1323 of the pass-2 processing shows the state after the instructions E(6) and F(7) have been processed. Referring to the segment information of the symbol table 1202, the instruction E(6) is visible by the two-byte instruction, while the instruction F(7) is visible by the three-byte instruction. Therefore, the value of the Label B(8) becomes "EH". The pass-2 processing has been completed in this way.
In the pass-3 processing, the code generating unit 1333 generates an object module file 1203, on the basis of the information which has been decided through the above pass-1 and pass-2 processings, then to be stored in the symbol table 1202. FIG. 17 is an assembly listing generated by processing the assembler program of FIG. 13.
In the assembly listing of FIG. 17, the generation instructions A(31), B(32), C(33), and D(34) are all generated by the two-byte instruction, so that any useless object code is not generated.
As mentioned above, the conventional assembler device of two-pass method has a defect of generating a useless code (NOP) if the data reference is made prior to the data definition (forward addressing) in case of making access to two memories having different object code length for access.
If the data reference is made after the data definition (backward reference), it has such a defect that the description of the assembler source is restricted, instead of generation of a useless code.
In case of the conventional assembler device of three-pass method, one pass, including one execution of processing through reading the input assembler program from the head to the end by one line, is added to the device of two-pass method, thereby to increase the processing time about 1.4 times longer, which is not practical.